package com.yeyks.controller.other;

import com.google.common.collect.Lists;
import com.yeyks.account.dal.domain.SysLog;
import com.yeyks.account.service.SysLogService;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.base.Arguments;
import com.yeyks.common.base.PageResult;
import com.yeyks.common.constants.SysLogMsg;
import com.yeyks.common.param.SysLogParam;
import com.yeyks.common.utils.ObjectConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 操作日志
 *
 * @author shuai
 * @date 2019-06-28
 */
@Slf4j
@Api(tags = "操作日志")
@RestController
@RequestMapping("/syslog")
public class SysLogController {
    @Autowired
    private SysLogService sysLogService;

    /**
     * 操作日志列表查询
     *
     * @return
     */
    @ApiOperation(value = "操作日志列表查询", response = SysLog.class)
    @PostMapping("/list")
    public AjaxResponseBody<PageResult<SysLog>> list(SysLogParam param) {
        PageResult<SysLog> pageResult = sysLogService.myList(param);
        return AjaxResponseBody.success(pageResult);
    }

    /**
     * 获取用户操作集合
     *
     * @return
     */
    @ApiOperation(value = "获取用户操作集合")
    @ApiImplicitParam(paramType = "query", name = "operatorName", value = "为空时查询全部", dataType = "String")
    @PostMapping("/operator")
    public AjaxResponseBody<List<String>> operator(@RequestParam(name = "operatorName", required = false) String operatorName) {
        List<String> valueToLists = ObjectConvertUtil.getPropertyValueToList(SysLogMsg.class);
        if (Arguments.strIsNull(operatorName)) {
            return AjaxResponseBody.success(valueToLists);
        }
        List<String> resultLists = Lists.newArrayList();
        for (String valueToList : valueToLists) {
            if (valueToList.contains(operatorName)) {
                resultLists.add(valueToList);
            }
        }
        return AjaxResponseBody.success(resultLists);
    }

}
